package textBuddyProcessor;

import java.io.File;
import java.io.IOException;

/*
 * ==============NOTE TO USER==========================================
 * This class is the Input Processor, to check if the file can be created
 * and return any error messages.
 * ====================================================================
 */

public class InputProcessor {
	private static final String ERROR_MESSAGE = "Sorry the file could not be created";
	private static final String READY_MESSAGE = "The file is ready for use";
	private static final String ADD_MESSAGE = "New File \\ %1$s"
			+ " \\ has been created to the current directory";

	public void setEnvironment(String args, ControllerLogic begin) {
		begin.setFileName(args);

		begin.setExistingFile(new File(begin.getFileName()));
		if (!begin.getExistingFile().exists()) {
			try {
				begin.getExistingFile().createNewFile();
				System.out.println(String.format(ADD_MESSAGE, args));

			} catch (IOException e) {
				printErrorMessage(ERROR_MESSAGE);
				System.exit(0);
			}

		}

	}

	private void printErrorMessage(String errorMessage) {
		System.out.println(errorMessage);
	}

	public void printReadyMessage() {
		System.out.println(READY_MESSAGE);
	}

}
